package cn.edu.scau.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.scau.entity.PictureArticle;
import cn.edu.scau.service.PictureArcticleService;

@Controller
@RequestMapping("/picture")
public class PictureTest {

	@Autowired
	private PictureArcticleService<PictureArticle> PictureArcticleService;

	public PictureArcticleService<PictureArticle> getPictureArcticleService() {
		return PictureArcticleService;
	}

	public void setPictureArcticleService(PictureArcticleService<PictureArticle> pictureArcticleService) {
		PictureArcticleService = pictureArcticleService;
	}

	@RequestMapping("/save")
	public String save() {

		PictureArticle pictureArticle = new PictureArticle();
		pictureArticle.setArticleUrl("2");
		pictureArticle.setColumnId(25);
		pictureArticle.setPictureUrl("sdfasdf");
		this.getPictureArcticleService().add(pictureArticle);

		return "NewFile";
	};

	@RequestMapping("/delete")
	public String delete(@RequestParam(name = "id") Integer id) {

		PictureArticle pictureArticle = this.getPictureArcticleService().getPictureArcticle(2);
		pictureArticle.setArticleUrl("kkkkkkk");
		this.getPictureArcticleService().update(pictureArticle, pictureArticle.getPictureArticle_id());
		this.getPictureArcticleService().delete(3);

		return "NewFile";
	};

	@RequestMapping("/update")
	public String update() {
		return "NewFile";
	};

	@RequestMapping("/findbypage")
	public String findByPage() {

		System.out.println(this.getPictureArcticleService().getPictureArcticles().size());
		return "NewFile";
	};

}
